# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
脚本类，用来对组合好的参数进行循环执行，依次带入组合参数请求。可加入对响应结果断言） 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

import pymysql
import requests

from baseset.msbxloanApi import API_MSBX
from logger import Logger

logger = Logger("msbxloan").get_log()


c_url = 'https://test.bx.msxiaodai.com/biz/'             # 企业端
u_url = 'https://test.bxadmin.msxiaodai.com/manage/'     # 业务端

db = pymysql.connect(
        host="10.16.20.182",
        # host="10.16.20.190",     # 开发环境
        user="dev",  # 测试：dev   开发：root
        password="dev",  # 测试：dev   开发：123456
        port=3306,
        use_unicode=True,
        charset="utf8",
        database="bxloandb")
cursor = db.cursor()

u_headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36',
            'content-Type': 'application/json',
            "Cookie": "admint=61f6a775d1110cc74b67b0505cd100615bcf64a2; adminhostid=2"
        }

user_cookie ={
    "1": "admint=778a2ada4e8a81b6a3f6d59f13772e6a84acbf60; adminhostid=4",
    "2": "admint=778a2ada4e8a81b6a3f6d59f13772e6a84acbf60; adminhostid=4",
    "3": "admint=d176aa5c24b08cb6b9297a5ac9de04ba1f5229d4; adminhostid=1",
    "4": "admint=d176aa5c24b08cb6b9297a5ac9de04ba1f5229d4; adminhostid=1"
}


# 业务端接口

# 1. 开户审核流程
def approveEnterprise(userId,enterpriseNo):
    logger.info('后台开户审核开始---------')
    fu_url = u_url + 'approveEnterprise'
    data = API_MSBX['approveEnterprise']
    data['enterpriseNo'] = enterpriseNo
    u_headers['Cookie'] = user_cookie[userId]
    req1 = requests.post(fu_url, json=data, headers=u_headers)
    print('被审批的企业号：' + enterpriseNo)
    logger.info("接口响应信息：%s", req1.text)


# 1. 获取我的待办
def task_fetch(userId):
    logger.info('我的待办案件查询开始---------')
    fu_url = u_url + '/task/fetch'
    data = API_MSBX['task_fetch']
    data['userId'] = userId
    u_headers['Cookie'] = user_cookie[userId]
    req1 = requests.post(fu_url, json=data, headers=u_headers)
    print('操作的用户id为：' + userId)
    logger.info("接口响应信息：%s", req1.text)
    data = eval(req1.text)['detail']['result']['pageList']
    for task in data:
        #print(type(task),task)
        processNo = task['processNo']
        processNum = task['processNum']
        taskId = task['taskId']
        print(userId,processNo,processNum,taskId)
        task_complete(userId, processNo, processNum, taskId)



def task_complete(userId,processNo,processNum,taskId):
    logger.info('审批提交申请开始---------')
    fu_url = u_url + '/task/complete'
    data = API_MSBX['task_complete']
    data['userId'] = userId
    data['processNo'] = processNo
    data['processNum'] = processNum
    data['taskId'] = taskId
    data['rtfState'] = "Pass"                # Pass-通过  Reject-拒绝  BackToFirst-退回初审 出纳时候直接写死pass
    u_headers['Cookie'] = user_cookie[userId]
    req1 = requests.post(fu_url, json=data, headers=u_headers)
    print('案件号为：' + processNum,'企业号为：' + processNum)
    logger.info("接口响应信息：%s", req1.text)



def main():
    pass

if __name__ == '__main__':
    #main()
    task_fetch('1')   # 风控审核角色1
    #task_fetch('2')    # 风控审核角色1
    #task_fetch('3')  # 财务岗角色1
    #task_fetch('4')  # 财务岗角色2
    #particulars('2',"SCD201906180001")